package com.gree.scmservice.controller.saas.admin;

import com.gree.common.entity.ReturnVo;
import com.gree.common.entity.TablePageData;
import com.gree.common.utils.MinIoUtil;
import com.gree.scmservice.entity.saas.SaasSysOrder;
import com.gree.scmservice.service.saas.SaasOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

/**
 * 包路径: com.gree.scmservice.controller.saas
 * 项目名: scm-api
 * 创建时间: 2021-07-13 9:58
 * 描述: TODO
 **/
@Api(tags = "系统订单信息(管理端)")
@RestController
@RequestMapping("/saas/admin/order")
public class AdminOrderController {

    @Autowired
    private SaasOrderService saasOrderService;

    /**
     * 查询系统订单信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询系统订单信息列表")
    @ApiImplicitParam(name = "saasSysOrder", value = "系统订单信息", dataType = "SaasSysOrder")
    public ReturnVo<TablePageData<SaasSysOrder>> list(SaasSysOrder saasSysOrder) {
        TablePageData<SaasSysOrder> saasSysOrderTablePageData = saasOrderService.selectOrderPage(saasSysOrder);
        return ReturnVo.success(saasSysOrderTablePageData);
    }

    /**
     * 获取系统订单信息详细信息
     */
    @GetMapping(value = "/{orderNo}")
    @ApiOperation(value = "获取系统订单信息详细信息")
    @ApiImplicitParam(name = "orderNo", value = "订单号", dataType = "String")
    public ReturnVo getInfo(@PathVariable("orderNo") String orderNo)
    {
        return ReturnVo.success(saasOrderService.getOrderNo(orderNo));
    }

    /**
     * 审批
     * @param orderNo
     * @param orderStatus 2:通过3:拒绝
     * @return
     */
    @PutMapping(value = "/status")
    @ApiOperation(value = "审批")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "orderNo", value = "订单号", dataType = "String"),
        @ApiImplicitParam(name = "orderStatus", value = "状态码(2:通过3:拒绝)", dataType = "int")
    })
    public ReturnVo updateStatusOrder(@RequestParam String orderNo, @RequestParam int orderStatus){
        return ReturnVo.toAjax(saasOrderService.updateStatusOrder(orderNo,orderStatus));
    }

    /**
     * 删除订单
     */
    @DeleteMapping("/{orderNos}")
    @ApiOperation(value = "删除系统订单信息")
    @ApiImplicitParam(name = "orderNos", value = "订单号", dataType = "String[]")
    public ReturnVo remove(@PathVariable String[] orderNos)
    {
        return ReturnVo.toAjax(saasOrderService.delOrderNos(orderNos));
    }

    /**
     * 下载文件
     */
    @GetMapping("/download")
    @ApiOperation(value = "下载支付信息")
    @ApiImplicitParam(name = "path", value = "支付信息图片", dataType = "String")
    public void download(@RequestParam String path, HttpServletResponse response) {
        saasOrderService.downloadPayCert(path, response);
    }
}
